<div class="comment-box">
<%= bootstrap_form_for [@commentable, @comment ] do |f| %>
  <%#= render "shared/error_message", :target => @comment %>

  <%= f.text_field :author_name, label: "名字" , class: "name_field" %>
  <div class="tabnav">
    <ul class="tabnav-tabs">
      <li><a href="#" class="tabnav-tab write-tab selected">编辑</a></li>
      <li><a href="#" class="tabnav-tab preview-tab">预览</a></li>
    </ul>
  </div>
  <%= f.text_area :body, hide_label: true %>
  <%= f.submit '提交', data: { disable_with: "提交中...." }, class: "btn btn-success" %>
<% end %>

</div>

<% content_for :template_js do %>
<script>
  $(".preview-tab").click(function(){
    $(".write-tab").removeClass("selected");
    $(this).addClass("selected");
    var b = $(".comment-box .form-group").last();
    var preview_content = b.find("textarea").val();
    b.find("textarea").hide();
    b.prepend("<div class='preview-box markdown-format' id='preview-box'>加载中...</div>");
    $.ajax({type: "POST", url: "/comment_preview", data: {content: preview_content} });

    return false;	
  });

  $(".write-tab").click(function() {
  	$(".preview-tab").removeClass("selected");
  	$(this).addClass("selected");
  	var b = $(".comment-box .form-group");
  	$(".preview-box").remove();
  	b.find('textarea').show();
  	return false;
  });
</script>
<% end %>